import sys
import pandas as pd
import json

def Cfunc(tar,num):
    with open("./testPro/conf/config.json",'r') as lf:
        config = json.load(lf)
    if 'ali' in tar:
        x = num
        y = config['ali-calculate']['y']
        z = config['ali-calculate']['z']
        c = config['ali-calculate']['c']
        return (x+y +z)*c
    elif 'tcnt' in tar:
        x = num
        y = config['tcnt-calculate']['y']
        z = config['tcnt-calculate']['z']
        c = config['tcnt-calculate']['c']
        return x+y*c+z
    elif 'bai' in tar:
        x = num
        y = config['bai-calculate']['y']
        z = config['bai-calculate']['z']
        c = config['bai-calculate']['c']
        return x+y*c+z

if __name__ == "__main__":


    sheet = pd.read_excel('./testPro/output/'+sys.argv[1]+'.xlsx', engine='openpyxl',sheet_name=0)
    if 'ali' in sys.argv[1]:
        print("阿里云 年费价格计算")
        for label, ser in sheet['yearlyPrice'].items():
            try:
                temp = float(ser)
                temp = Cfunc(sys.argv[1],temp)
                sheet.loc[label, 'yearlyPrice(calculated)'] = temp
            except:
                continue
    if 'bai' in sys.argv[1]:
        print("百度云 年费价格计算")
        for label, ser in sheet['year_price'].items():
            try:
                temp = float(ser)
                temp = Cfunc(sys.argv[1],temp)
                sheet.loc[label, 'yearlyPrice(calculated)'] = temp
            except:
                continue
    if 'tcnt' in sys.argv[1]:
        print("腾讯云 年费价格计算")
        for label, ser in sheet['包年(元)'].items():
            try:
                temp = float(ser)
                temp = Cfunc(sys.argv[1],temp)
                sheet.loc[label, 'yearlyPrice(calculated)'] = temp
            except:
                continue

    sheet.to_excel('./testPro/output/'+sys.argv[1]+'.xlsx',index=False)
